/* 

Walter, Stefanie (2016). Crisis Politics in Europe: Why austerity is easier to implement 
	in some countries than in others. Comparative Political Studies
	
								**************************
									REPLICATION FILE
								**************************
	
15 October 2015


Table of Contents:
------------------
1. Macro-Level Analysis : National Vulnerability Profiles
		Figures 2 and 4, Tables 1, A2, A3, A4

2. Micro-Level Analysis: Distributive Outcome
		Figure 3, Tables A6, A7, A8
3. Cabinet Ideology
		Tables 1 and A5

*/



cd "/Users/walter/Documents/Papers/2015.CPS.Walter/FINAL.CPS.2016/Replication/"
log using Walter.CPS.Replication_log, replace


* ========================================================
* 1. Macro-Level Analysis: National Vulnerability Profiles
* ========================================================
* Figures 2 and 4, Tables 1, A2, A3, A4

clear
use walter.cps.macrodata.dta


* Label  variables
* ------------------------------------
label var inflation2007 "Inflation rate 2007 (Eurostat)"
label var inflation2009 "Inflation rate 2009 (Eurostat)"
label var exportsgdp2007 "Exports goods+services, % of GDP 2007 (Eurostat)" 
label var exportsgdp2009 "Exports goods+services, % of GDP 2009 (Eurostat)" 
label var niip2007 "Net International Investment Position, % of GDP 2007 (EC, Stat. Annex Alert Mechanism Report, Tab 3.3)"
label var niip2009 "Net International Investment Position, % of GDP 2009 (EC, Stat. Annex Alert Mechanism Report, Tab 3.3)"
label var gov_sector_debt2007 "General Government sector Debt, % of GDP 2007 (EC, Stat. Annex Alert Mechanism Report, Tab 3.13)"
label var gov_sector_debt2009 "General Government sector Debt, % of GDP 2009 (EC, Stat. Annex Alert Mechanism Report, Tab 3.13)"
label var unemployment2007 "Unemployment rate in %, 2007 annual avg (Eurostat)"
label var unemployment2009 "Unemployment rate in %, 2009 annual avg (Eurostat)"
label var avg3yrunemp2007 "3 years average of Unemployment Rate 2007 (EC, Stat. Annex Alert Mechanism Report, Tab 3.14)"
label var avg3yrunemp2009 "3 years average of Unemployment Rate 2009 (EC, Stat. Annex Alert Mechanism Report, Tab 3.14)"
label var currentaccount2007 "Current account balance 2007 (Eurostat)"
label var currentaccount2009 "Current account balance 2009 (Eurostat)"
label var curracc_3yr2007 "3 year avg Current Account Balance 2007, % GDP (EC, Stat. Annex Alert Mechanism Report, Tab 3.1)"
label var curracc_3yr2009 "3 year avg Current Account Balance 2009, % GDP (EC, Stat. Annex Alert Mechanism Report, Tab 3.1)"
label var extdebt2007 "Net External Debt, % of GDP 2007 (EC, Stat. Annex Alert Mechanism Report, Tab 3.22)"
label var extdebt2009 "Net External Debt, % of GDP 2009 (EC, Stat. Annex Alert Mechanism Report, Tab 3.22)"
label var nonfin_extdebt2007 "External debt of non-financial private sector in % of all debt 2007 (own calculation, based on BIS http://www.bis.org/statistics/credtopriv.htm)"
label var nonfin_extdebt2009 "External debt of non-financial private sector in % of all debt 2009 (own calculation, based on BIS http://www.bis.org/statistics/credtopriv.htm)"
label var forex_snb2007 "% Foreign currency borrowing, non-financial private sector, 2007 (Brown et al. 2009)"
label var xrregimerr2007 "de facto exchange rate classification 2007, 1=currency union, 12=free float (Ilzetzki/Reinhart/Rogoff)"
label var emu2007 "EMU Member 2007"
label var emu2009 "EMU Member 2009"
label var rigidemployment2007 "Rigidity of employment, 100=worst, 2007 (World Bank Doing Business,cited in WEF Glob. Competitiveness Report 2008/9, Tab 7.04)"
label var rigidemployment2009 "Rigidity of employment, 100=worst, 2009 (World Bank Doing Business,cited in WEF Glob. Competitiveness Report 2010/11, Tab 7.04)"
label var govsurplus2007 "Government deficit(-)/surplus(+) 2007 (Eurostat)"
label var govsurplus2009 "Government deficit(-)/surplus(+) 2009 (Eurostat)"
	

* ================================
* Recode variables
* ================================

* Government Deficit
* -----------------------------------------
* General Government Surplus (+)/Deficit (-)
* Source: Eurostat (downloaded 5..8.15)
* http://ec.europa.eu/eurostat/tgm/table.do?tab=table&plugin=1&language=en&pcode=teina200
* Public deficit/surplus is defined [...] as general government net borrowing/lending according to the European System of Accounts. 
* The general government sector comprises central government, state government, local government, and social security funds. 

* Recoding so that higher values are Deficit

* Data for Greece is missing. I use data from the World Bank instead (note that figures are probably too low)
replace govsurplus2007=-6.5 if country=="Greece"
replace govsurplus2009=-15.2 if country=="Greece"

gen govsurplus0709=govsurplus2007
replace govsurplus0709=govsurplus2009 if emu2009==1
label var govsurplus0709 "Government surplus, 2007(EMU:2009)"



* Rigidity of Employment
* ------------------------------------------------------------
* Source: WEF Global Competitiveness Reports; based on World Bank Data from "Doing BUsiness Report"
* 2007: http://www.weforum.org/reports/global-competitiveness-report-2008-2009 Table 7.02
* 2009: http://www3.weforum.org/docs/WEF_GlobalCompetitivenessReport_2010-11.pdf Table 7.02
* The rigidity of employment index is the average of 3 subindices: a difficulty of hiring index, a rigidity of hours index and
* a difficulty of firing index.
* More info on Index can be found here: http://www.doingbusiness.org/~/media/GIAWB/Doing%20Business/Documents/Annual-Reports/English/DB08-FullReport.pdf

* No data for Cyprus 2007: Impute data from 2009
replace rigidemployment2007=rigidemployment2009 if country=="Cyprus"
* No data for Malta 2007: Use average values: 42.7 (2007) and 35.04 (2009)
replace rigidemployment2007=42.7 if country=="Malta"
replace rigidemployment2009=35.04 if country=="Malta"

gen rigidemployment0709=rigidemployment2007
replace rigidemployment0709=rigidemployment2009 if emu2009==1
label var rigidemployment0709 "Rigidity of employment, 2007(EMU:2009)"


* Inflation Rate
* ------------------------------------------------------------
* Source:  Eurostat (download 3.8.15)
* http://ec.europa.eu/eurostat/tgm/table.do?tab=table&init=1&language=de&pcode=tec00118&plugin=1
* HICP - inflation rate
* Harmonised Indices of Consumer Prices (HICPs) are designed for international comparisons of consumer price inflation.

gen inflation0709=inflation2007
replace inflation0709=inflation2009 if emu2009==1
label var inflation0709 "Inflation Rate, 2007(EMU:2009)"


* Exports of goods and services in % of GDP
* ------------------------------------------------------------
* Source:  Eurostat (download 3.8.15)
* http://ec.europa.eu/eurostat/tgm/table.do?tab=table&init=1&plugin=1&language=en&pcode=tet00003
* Exports of goods and services in % of GDP

* Data are multiplied by -1 so that a higher number implies a lower export share

gen exports2007=exportsgdp2007*(-1)
label var exports2007 "Exports in % of GDP (reversed: higher values=less exports), 2007)"

gen exports0709=exportsgdp2007*(-1)
replace exports0709=exportsgdp2009*(-1) if emu2009==1
label var exports0709 "Exports in % of GDP (reversed: higher values=less exports), 2007(EMU:2009))"



* Net International Investment Position (NIIP), in % of GDP
* ------------------------------------------------------------
* Source: European Commission, Statistical Annex Alert Mechanism Report 2014, Tab 3.3
* http://ec.europa.eu/economy_finance/economic_governance/documents/alert_mechanism_report_2015_statistical_annex_en.pdf
* International investment position (IIP) statistics record the net financial position (assets minus liabilities) of a country vis-�-vis the rest
* of the world. Data cover stocks of direct and portfolio investments, financial derivatives and other investment and reserve assets. 
* If the net IIP is very negative, the domestic sectors of the economy are indebted toward the rest of the world. 
* The net IIP is the stock counterpart to the current plus capital account balance.

* Data are multiplied by -1 so that a higher number implies net debts towards the rest of the world

gen niip_rev2007=niip2007*(-1)
label var niip_rev2007 "NIIP (reversed: higher values=more debt), 2007)"

gen niip_rev0709=niip2007*(-1)
replace niip_rev0709=niip2009*(-1) if emu2009==1
label var niip_rev0709 "NIIP (reversed: higher values=more debt), 2007(EMU:2009)"



* General Government sector Debt, % of GDP
* ----------------------------------------
* Source: European Commission, Statistical Annex Alert Mechanism Report 2014, Tab 3.13
* http://ec.europa.eu/economy_finance/economic_governance/documents/alert_mechanism_report_2015_statistical_annex_en.pdf
* Consolidated general government gross debt at nominal value, outstanding at the end of the year. 
* The general government sector comprises central government, state government, local government, and social security funds

gen gov_sector_debt0709=gov_sector_debt2007
replace gov_sector_debt0709=gov_sector_debt2009 if emu2009==1
label var gov_sector_debt0709 "General Government sector Debt, % of GDP, 2007(EMU:2009)"


* Unemployment Rate
* ---------------------------------
* Source:  Eurostat (download 3.8.15)
* http://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=une_rt_a&lang=en
* Unemployment rate  - annual average, in %

gen unemployment0709=unemployment2007
replace unemployment0709=unemployment2009 if emu2009==1
label var unemployment0709 "Unemployment rate in %, 2007(EMU:2009)"


* Average 3-year unemployment rate
* Source: European Commission, Statistical Annex Alert Mechanism Report 2014, Tab 3.14
* http://ec.europa.eu/economy_finance/economic_governance/documents/alert_mechanism_report_2015_statistical_annex_en.pdf
gen avg3yrunemp0709=avg3yrunemp2007
replace avg3yrunemp0709=avg3yrunemp2009 if emu2009==1
label var avg3yrunemp0709 "3yr average unemployment rate in %, 2007(EMU:2009)"

* Current Account Deficit
* ---------------------------------
* Source:  Eurostat (download 3.8.15)
* http://ec.europa.eu/eurostat/tgm/table.do?tab=table&language=en&pcode=tec00043
* Balance of the current account, as % of GDP

gen curraccdeficit2007=currentaccount2007*(-1)
label var curraccdeficit2007 "Current account deficit 2007"

gen curraccdeficit0709=currentaccount2007*(-1)
replace curraccdeficit0709=currentaccount2009*(-1) if emu2009==1
label var curraccdeficit0709 "Current account deficit 2007 (EMU:2009)"


* Net External debt
* -----------------------------------
* Source: European Commission, Statistical Annex Alert Mechanism Report 2014, Tab 3.22
* http://ec.europa.eu/economy_finance/economic_governance/documents/alert_mechanism_report_2015_statistical_annex_en.pdf

* data is missing for Slovakia in 20076. I impute this datapoint by using the 2008 value (17.5)
replace extdebt2007=17.5 if country=="Slovakia"

gen extdebt0709= extdebt2007
replace extdebt0709=extdebt2009 if emu2009==1
label var extdebt0709 "Net External Debt, % of GDP 2007 (EMU_2009)"


* Foreign currency exposure
* -----------------------------------
* Eastern Eureopan countries:forex_snb2007 
* Source: Brown, Martin, Marcel Peter, and Simon Wehrm�ller. 2009. Swiss Franc Lending in Europe. Z�rich: Swiss National Bank. numbers based on Table 2

* Exposure for EMU countries must be estimated: 
* Euro exit would mean in principle that all euro loans turn into forex loans (100% exposure).
* This is unlikely to happen. I approximate the forex exposure by calculating the share of non-financial private sector debt
* that does not come from domestic banks (i.e. debt from foreign intermediaries or debt securities).
* The assumption is that mandating a conversion of loans from domestic banks into a new national currency 
* would be easier for the government than mandating a conversion of these other types of debt. 
* This estimate is likely to be a conservative estimate and does not contain the currency risks by financial institutions 
* (but these are likely to be highly correlated with the external debt variable)
* "External debt of non-financial private sector in % of all debt 2009 (own calculation, based on BIS http://www.bis.org/statistics/credtopriv.htm)"


* data is missing for Slovakia, Malta and Cyprus. I impute this datapoint by using the average value of nonfin_extdebt: 40.08 (2007) and 41.59 (2009) and forex_snb2007 (40.41)
replace nonfin_extdebt2007=40.08 if country=="Slovakia" | country=="Malta" | country=="Cyprus"
replace nonfin_extdebt2009=41.59 if country=="Slovakia" | country=="Malta" | country=="Cyprus"
replace forex_snb2007=40.41 if country=="Slovakia" | country=="Malta" | country=="Cyprus"

* Generate overall forex exposure variable:
* forex_snb2007 for non-EMU members and nonfin_extdebt2007/09 for EMU members

* all 2007
gen forexexposure2007=forex_snb2007
replace forexexposure2007= nonfin_extdebt2007 if emu2007==1
* use BIS data for Slovenia
replace forexexposure2007= forex_snb2007 if country=="Slovenia"
label var  forexexposure2007 "Foreign currency exposure non-financial sector (estimate) 2007"

* 2007 for EE sample and 2009 for EMU
gen forexexposure0709=forex_snb2007
replace forexexposure0709= nonfin_extdebt2009 if emu2009==1
label var  forexexposure0709 "Foreign currency exposure non-financial sector (estimate) 2007(EMU:2009)"

* Different assumption: 50% of all loans will be foreign currency loans in EMU countrie (either non-financial or financial sector will be hit)
gen forexexp2=forex_snb2007
replace forexexp2= 50 if emu2009==1
label var  forexexp2 "Foreign currency exposure"



* Exchange Rate Regime classification
* -----------------------------------
* Source: http://personal.lse.ac.uk/ilzetzki/data/ERA-Annual%20fine%20class.xls

* Recode value for Latvia: ERM II member=2
* IRR code as 11 (highly flexible), but this is inconsistent with their more detailed country study and Latvia's ERM membership
replace xrregimerr2007=2 if country=="Latvia" 

* recode variable so that more fixed regimes have higher values
gen xrregime=xrregimerr2007*(-1)+13
label var xrregime "Exchange rate regime (1=free float 12=currency union)

* Recode (future) EMU countries as 12
replace xrregime=12 if emu2009==1


* Recode into coarse classification (based on Reinhart/Rogoff)
gen xrcoarse=1
replace xrcoarse=2 if xrregimerr2007>4 & xrregimerr<9
replace xrcoarse=3 if xrregimerr2007>8 & xrregimerr<12
replace xrcoarse=4 if xrregimerr2007>11
label var xrcoarse "XR Regime, coarse classification"


* ================================
* Generate relevant sample
* ================================
* Sample includes the 8 Eastern European countries plus those EMU memberstates (or soon to be members) 
* recording a current account deficit in 2007

drop if eesample==.
drop if eesample==0 & currentaccount2007>=0
drop if country=="Slovakia"
* drop if eesample==0 & emu2007==0

* ================================
* Descriptive Statistics
* ================================
sort eesample country

global external07 extdebt2007 forexexposure2007  niip2007  exportsgdp2007 inflation2007  currentaccount2007
global internal07    rigidemployment2007  unemployment2007 gov_sector_debt2007 govsurplus2007 



* ----------------------------------------------------------------------------------------------
* TABLE 1: Variable Values
* ----------------------------------------------------------------------------------------------
l country emu2009 $external07 $internal07 

* ----------------------------------------------------------------------------------------------
* TABLE A2: Summary Statistics: Macrolevel Analysis
* ----------------------------------------------------------------------------------------------
sum $external07 $internal07 


* Principal Components Analysis
* ================================

* External Adjustment, 2007 values
* -----------------------------------
* Note: I do not include the exchange rate regime or the import content of exports, because they have a negative
* eigenvector, hence decreasing costs of adjustment, rather than increasing costs

global external07 extdebt2007 forexexposure2007  niip2007  exportsgdp2007 inflation2007  

* ----------------------------------------------------------------------------------------------
* TABLE A4: Results of Principal Components Analysis: Potential Cost of External Adjustment
* ----------------------------------------------------------------------------------------------
pca $external07
screeplot
loadingplot
scoreplot, mlabel(country)
estat kmo
estat loadings
predict pce107 pce207 pce307, score
label var pce107 "Cost of external adjustment (PCA-based index)"

corr pce107 $external07 


* Internal Adjustment, 2007 values
* -----------------------------------
global internal07    rigidemployment2007  unemployment2007 gov_sector_debt2007 govsurplus2007  

* Note: I do not include the current account deficit or unit labor costs, because they have a negative
* eigenvector, hence decreasing costs of adjustment, rather than increasing costs

* ----------------------------------------------------------------------------------------------
* TABLE A4: Results of Principal Components Analysis: Potential Cost of Internal Adjustment
* ----------------------------------------------------------------------------------------------
pca $internal07
screeplot
loadingplot
scoreplot, mlabel(country)
estat kmo
estat loadings
predict pci107 pci207 pci307, score
label var pci107 "Cost of internal adjustment (PCA-based index)"



* VULNERABILITY PROFILES
* ================================

* Eastern European Sample
* ------------------------
gen pos=3
replace pos=5 if country=="Slovenia"
replace pos=8 if country=="Lithuania"
replace pos=1 if country=="France"
replace pos=7 if country=="Slovakia"
replace pos=2 if country=="Romania"
replace pos=11 if country=="Czech Republic"
replace pos=3 if country=="Poland"
replace pos=7 if country=="Italy"
replace pos=8 if country=="Spain"
replace pos=12 if country=="Malta"

gen exlabel=4
replace exlabel=-4 if country=="Poland"
replace exlabel=-4 if country=="Czech Republic"
gen inlabel=4
replace inlabel=-4 if country=="Czech Republic"
replace inlabel=-4 if country=="Latvia"

gen typevar=.
replace typevar=1 if country=="Poland"
replace typevar=2 if country=="Hungary"
replace typevar=4 if country=="Czech Republic"
replace typevar=3 if country=="Latvia"
label def typevar4 1 "vulnerability profile I" 2 "vulnerability profile II" 3 "vulnerability profile III" 4 "vulnerability profile IV"
label def typevar3 1 "I - H: external adjustment, little conflict" 2 "H: mixed adjustment, severe conflict - II" ///
	3 "H: internal adjustment, little conflict - III" 4 "IV - H: strategy unclear, no conflict"
label val typevar typevar4

gen poslab=3
replace poslab=9 if typevar==2				
replace poslab=9 if typevar==3				
				

gen curraccdef3y=(-1)*curracc_3yr2007		

* -------------------------------------------------------------------------------------------
* Figure 2: Vulnerability Profiles of eight Eastern European countries
* -------------------------------------------------------------------------------------------
* Note:  Markers are weighted by the average current account deficit 2005-07		

twoway (scatter pci107 pce107 [w=curraccdef3y] if eesample==1 ,  msymbol(circle)  mcolor( ebblue) legend(off)  ///
		xscale(range(-4 4)) xlabel(-4 -2 0 2 4) yscale(range(-4 4)) ylabel(-4 -2 0 2 4) yline(0) xline(0) scheme(s1color) ) ///
	(scatter pci107 pce107 if eesample==1  , mlabel(country) mlabvpos(pos) mcolor( ebblue) mlabcolo( black) ) ///
		(scatter inlabel exlabel, yaxis(2) ytitle("", axis(2)) ylabel(#0, axis(2)) xaxis(2) xtitle("", axis(2)) xlabel(#0, axis(2)) ///
		mlabel(typevar) mlabvpos(poslab)  mcolor( white) mlabcolo( black)) 

		
* -------------------------------------------------------------------------------------------
* Figure 3: Vulnerability Profiles of EMU deficit and Eastern European countries, 2007 values
* -------------------------------------------------------------------------------------------
* Note:  Markers are weighted by the average current account deficit 2005-07		

	
* Markers are weighted by the average current account deficit 2005-07						
twoway (scatter pci107 pce107 [w=curraccdef3y] , msymbol(circle_hollow) mcolor(navy)  ///
		xscale(range(-4 4)) xlabel(-4 -2 0 2 4) yscale(range(-4 4)) ylabel(-4 -2 0 2 4) yline(0) xline(0)) ///
	(scatter pci107 pce107 if eesample==1  , mlabel(country) mlabcolor(ebblue) mlabvpos(pos) msize(big) mcolor(ebblue) ) /// 
	   (scatter  pci107 pce107 if eesample==0  , mlabel(country) msymbol(c) msize(small) mlabvpos(pos) mcolor(navy) mlabcolo(black)  ///	   	
		legend(order(1 "Eastern Europe" 3 "EMU deficit country")   rows(1)) ///
				scheme(s1color)  ) ///
						(scatter inlabel exlabel, yaxis(2) ytitle("", axis(2)) ylabel(#0, axis(2)) xaxis(2) xtitle("", axis(2)) xlabel(#0, axis(2)) ///
		mlabel(typevar) mlabvpos(poslab)  mcolor( white) mlabcolo( black)) 



		
				
* ================================
* Appendix
* ================================
* Table in Appendix that lists component parts of indeces as well as principal component scores

* Sort by Sample and costs of external adjustment
sort eesample country  pce107 pci107

* -----------------------------------------------------------------------------------------------------------
* Table A3: Variable Values used in the analysis and PCA-based predicted values for principal component 1
* -----------------------------------------------------------------------------------------------------------
l country  $external07 pce1 $internal07 pci107


* ================================
* ROBUSTNESS
* ================================

* ---------------------------------------------------------------------
* USING 2009 Values for EMU countries
* ---------------------------------------------------------------------
* Ordering in general remains robust, but cost of internal adjustment rises significantly for EMU countries.
* This is not surprising given that they had already experienced two years of global financial crisis up to this point,
* generating significant problems for government debt and deficits as well as unemployment.

* Compared to the situation of EMU crisis, the cost of internal adjustment to all Eastern European countries except Hungary
* is below average

* External Adjustment
* -----------------------------------
global external09 extdebt0709 forexexposure0709  niip_rev0709  exports0709 inflation0709  

pca $external09
estat kmo
estat loadings
predict pce109 pce209 pce309, score
label var pce109 "Cost of external adjustment (First principal component)"

* Internal Adjustment, 2007 values
* -----------------------------------
global internal09    rigidemployment0709  unemployment0709 gov_sector_debt0709 govsurplus0709 

pca $internal09
estat kmo
estat loadings
predict pci109 pci209 pci309, score
label var pci109 "Cost of internal adjustment (First principal component)"

* COST PROFILES
* --------------------
twoway (scatter pci109 pce109 if eesample==1, mlabel(country) mlabvpos(pos)  yline(0) xline(0)) ///
	   (scatter  pci109 pce109 if eesample==0, mlabel(country) msymbol(D) mlabvpos(pos) mcolor(red) ///	   	
		legend(label(1 "Eastern Europe") label(2 "EMU deficit country") )  )

		
* ========================================================
* 2. Micro-Level Analysis: Distributive Outcome
* ========================================================
* Figure 3, Tables A6, A7, A8

clear

* Data: European Social Survey (ESS), Round 5, conducted October 2010
use ESS5_2010_modified.dta	

* Recode Variables

gen weight=dweight*pweight

gen eesample=0
replace eesample=1 if cntry=="CZ"
replace eesample=1 if cntry=="EE"
replace eesample=1 if cntry=="HU"
replace eesample=1 if cntry=="PL"

gen voter=vote==1

gen votertype=1 // opposition voters
replace votertype=0 if vote==2 // non-voters
replace votertype=. if prtclcee==. & ee==1 // no voting info
replace votertype=. if prtcldpl==. & pl==1 // no voting info
replace votertype=. if prtclchu==. & hu==1 // no voting info
replace votertype=. if prtclbcz==. & cz==1 // no voting info

gen voterblank=votertype

label def votertype 0 "non-voter" 1 "opposition voter" 2 "government voter"
label val votertype votertype

* coding by country and party, government party information from ParlGov database
* Cabinet in place for most of the time between August 2008 and Octover 2010 (survey month)

/* Estonia
-----------------
Eesti Reformierakond (Estonian Reform Party)
IRL	 Erakond Isamaa ja Res ... (Union of Pro Patria */
replace votertype=2 if  prtclcee==1
replace votertype=2 if  prtclcee==3
replace votertype=2 if prtclcee==. & prtvtcee==3
replace votertype=2 if prtclcee==. & prtvtcee==1


/* Poland
-----------------
PO	 Platforma Obywatelska (Civic Platform)	 209	 240	460	 ?	 6.2
PSL	 Polskie Stronnictwo Ludowe (Polish Peasants' Party)	 31	 240	460		 4.2*/
replace votertype=2 if  prtcldpl==3
replace votertype=2 if  prtcldpl==5
replace votertype=2 if  prtcldpl==. & prtvtbpl ==3
replace votertype=2 if  prtcldpl==. & prtvtbpl ==5


/* Hungary
-----------------
Government in Hungary changed only a few months before the survey (25.4.2010)
Analysis uses voters of old governing parties: MSZP	 Magyar Szocialista P�rt (Hungarian Socialist Party) */	
replace votertype=2 if  prtclchu==4
replace votertype=2 if prtclchu==. & prtvtchu==4

* Gov in Oct 10: Fidesz	 Fidesz � Magyar Polg�ri ... (Fidesz �- Hungarian Civic ...)	 227	 263	386	 ?	 6.5
* KDNP	 Kereszt�nydemokrata N�pp�rt (Christian Democratic People's Party)	 36	 263	386		 7.4 */
gen votercurrentgov=voterblank
replace votercurrentgov=2 if  prtclchu==1
replace votercurrentgov=2 if prtclchu==. &  prtvtchu==1


/* Czech Republic
-----------------
* Government in CZ changed only a few months before the survey (28.6.12010). 
* Voters of old governing parties; technocratic gov supported by 
*  Civic Democratics (ODS), Social Democrats (CSSD), Greens (SZ) and won an investiture vote on 7 June (yes: 156).
* these parties are not counted because they only tolerated the government.
* Before that: Government by Civic Democratics (ODS), Christian Democratic Union (KDU-CSL), Greens (SZ) */ 

replace votertype=2 if prtclbcz==7
replace votertype=2 if  prtclbcz==3
replace votertype=2 if  prtclbcz==2
replace votertype=2 if prtclbcz==. & prtvtbcz==3
replace votertype=2 if prtclbcz==. & prtvtbcz==7
replace votertype=2 if prtclbcz==. & prtvtbcz==2


* Gov in Oct 10: ODS	 Ob?ansk� demokratick� strana (Civic Democratic Party)	 53	 118	200	 ?	 7.4
* TOP09	 Tradice Odpov?dnost Prosperita 09 (Tradition Responsibility Prosperity 09)	 41	 118	200		
* VV1	 V?ci ve?ejn� (Public Affairs)	 24	 118	200	*/
replace votercurrentgov=2 if  prtclbcz==7
replace votercurrentgov=2 if prtclbcz==5
replace votercurrentgov=2 if  prtclbcz==6

*replace votercurrentgov=2 if prtclbcz==. & prtvtbcz==7
*replace votercurrentgov=2 if prtclbcz==. & prtvtbcz==5
*replace votercurrentgov=2 if prtclbcz==. & prtvtbcz==6

replace votertype=0 if vote==2 // non-voters
replace votercurrentgov=0 if vote==2 // non-voters

label val votertype votertype
label val votercurrentgov votertype



* Government, Opposition, and Non-voters, based on votertype2
gen govvoter=votertype==2
replace govvoter=. if votertype==.

gen oppvoter=votertype==1
replace oppvoter=. if votertype==.

gen nonvoter=votertype==0
replace nonvoter=. if votertype==.


* Current government: Government, Opposition, and Non-voters, based on votertype2
gen currgovvoter=votercurrentgov==2
replace currgovvoter=. if votercurrentgov==.

gen curroppvoter=votercurrentgov==1
replace curroppvoter=. if votercurrentgov==.

gen currnonvoter=votercurrentgov==0
replace currnonvoter=. if votercurrentgov==.



* Distinguish between non-voters and people not eligible to vote
gen votertype3=.
* replace votertype3=0 if vote==3
replace votertype3=1 if vote==2
replace votertype3=2 if votertype==1
replace votertype3=3 if votertype==2
label define votertype3 0 "Not-eligible" 1 "Non-voter" 2 "Voter Opposition" 3 "Voter Government"
label val votertype3 votertype3


gen land=.
replace land=1 if ee==1
replace land=2 if hu==1
replace land=3 if cz==1
replace land=4 if pl==1
label def land 1 "EE, internal" 2 "HU, mixed" 3 "CZ, external" 4 "PL, external"
* label def land 1 "EE, internal, center-right" 2 "HU, mixed, left" 3 "CZ, external, center" 4 "PL, external, center right"
label val land land

gen  land2=land
label def land2 1 "Estonia" 2 "Hungary" 3 "Czech Rep." 4 "Poland"
label val land2 land2





* ANALYSIS
* ==========
*Effects of crisis on different voter groups in the past three years: Using gov during most of the crisis

* -----------------------------------------------------------------------------------------------------------
* Figure 3: Impact of crisis on households, by voter group
* -----------------------------------------------------------------------------------------------------------


graph dot mlohinc  dsdclve   if eesample==1 [pweight=dweight], over(votertype) over(land) ylabel(0 "not at all" 1 2 3 4 5 6 "a great deal    ") ///
	marker(1, mcolor(gs9)) marker(2, msymbol(T)  mcolor(gs4)) ///
	legend(subtitle("Over the past three years...") ///
	label(1 "Household had to manage on lower household income.") ///
	label(2 "Household had to draw on savings/debt to cover ordinary living expenses.") ///
	 col(1)) ///
	scale(0.78) 

* T-tests	
* ------------------------------------------
ttest dsdclve if cntry=="EE", by(govvoter) 
ttest dsdclve if cntry=="CZ", by(govvoter) 
ttest dsdclve if cntry=="PL", by(govvoter) 
ttest dsdclve if cntry=="HU", by(govvoter) 

ttest mlohinc if cntry=="EE", by(govvoter) 
ttest mlohinc if cntry=="CZ", by(govvoter) 
ttest mlohinc if cntry=="PL", by(govvoter) 
ttest mlohinc if cntry=="HU", by(govvoter) 	


* Bivariate Regression Analysis
* ------------------------------------------
reg mlohinc govvoter  if ee==1 [pw=dweight]
estimates store ee1
reg mlohinc govvoter  if cz==1 [pw=dweight]
estimates store cz1
reg mlohinc govvoter  if pl==1 [pw=dweight]
estimates store pl1
reg mlohinc govvoter  if hu==1 [pw=dweight]
estimates store hu1

* -----------------------------------------------------------------------------------------------------------
* Table A6: Bivariate Regression Analysis - Household had to manage on lower income
* -----------------------------------------------------------------------------------------------------------
estout  ee1  hu1 cz1 pl1 , cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) style(fixed) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) stats(N r2 r2_a F) 	

reg dsdclve govvoter if ee==1 [pw=dweight]
estimates store ee2
reg dsdclve govvoter if cz==1 [pw=dweight]
estimates store cz2
reg dsdclve govvoter if pl==1 [pw=dweight]
estimates store pl2
reg dsdclve govvoter if hu==1 [pw=dweight]
estimates store hu2

* -----------------------------------------------------------------------------------------------------------
* Table A6: Bivariate Regression Analysis - Household had to draw on savings
* -----------------------------------------------------------------------------------------------------------
estout  ee2  hu2 cz2 pl2 , cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) style(fixed) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) stats(N r2 r2_a F) 

	
* -----------------------------------------------------------------------------------------------------------
* Table A7: Mean values for subgroups
* -----------------------------------------------------------------------------------------------------------
table land votertype [pw=dweight], c(mean mlohinc) format(%9.3f)
table land votertype  [pw=dweight], c(mean dsdclve) format(%9.3f)


			
* Regression analysis of crisis impact and vote choice
* ------------------------------------------------------------------------------------------------------		

* Control variables

gen children=chldhm==1

gen govworker=tporgwk==1
gen publicsector=tporgwk==2
gen public=tporgwk<3
gen soe=tporgwk==3
gen privatefirm=tporgwk==4
gen selfemployed=tporgwk==5
gen otherwork=tporgwk==6

gen construction=sector==5
gen agriculture=sector==1
gen pubfinancing=sector==8
replace pubfinancing=0 if sector==8 & tporgwk>3
gen privfinancing=sector==8
replace privfinancing=0 if sector==8 & tporgwk<4

gen city=domicil<3
gen town=domicil==3
gen rural=domicil>3
replace rural=. if domicil==.

global controls inc union public soe selfemployed retire childr rural age gender educlv

* Household Income
* ----------------
reg mlohinc   $controls if ee==1 [pw=dweight]
estimates store ee1
reg mlohinc   $controls   if cz==1 [pw=dweight]
estimates store cz1
reg mlohinc   $controls if pl==1 [pw=dweight]
estimates store pl1
reg mlohinc  $controls if hu==1 [pw=dweight]
estimates store hu1

* ------------------------------------------------------------------------------------------------------		
* Table A8: Different constituencies and the impact of the crisis and vote choice, columns lower income
* ------------------------------------------------------------------------------------------------------		
estout  ee1  hu1 cz1 pl1 , cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) style(fixed) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) stats(N r2 r2_a F) 		

* Voting
* ----------------
logit govv  $controls if ee==1 [pw=dweight]
estimates store ee3
logit govv  $controls if cz==1 [pw=dweight]
estimates store cz3
logit govv   $controls  if pl==1 [pw=dweight]
estimates store pl3
logit govv  $controls  if hu==1 [pw=dweight]
estimates store hu3

* ------------------------------------------------------------------------------------------------------		
* Table A8: Different constituencies and the impact of the crisis and vote choice, columns government vote
* ------------------------------------------------------------------------------------------------------		

estout  ee3  hu3 cz3 pl3 , cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) style(fixed) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) stats(N r2 r2_a aic bic F ch2 p) 		
	


* Online Appendix: Table A9: Comparison of voters of past (crisis) vs. current government in Hungary 
* ------------------------------------------------------------------------------------------------------
reg stfec  govvo  if hu==1 [pw=dweight]
estimates store hu1
reg stfec currgovvoter   if hu==1 [pw=dweight]
estimates store hu2
reg mloh  govvo  if hu==1 [pw=dweight]
estimates store hu3
reg mloh currgovvoter   if hu==1 [pw=dweight]
estimates store hu4
reg dsdclve  govvo  if hu==1 [pw=dweight]
estimates store hu5
reg dsdclve currgovvoter   if hu==1 [pw=dweight]
estimates store hu6
reg cuthheq  govvo  if hu==1 [pw=dweight]
estimates store hu7
reg cuthheq currgovvoter   if hu==1 [pw=dweight]
estimates store hu8

estout   hu1  hu2  hu3 hu4 hu5 hu6 hu7 hu8, cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) style(fixed) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) stats(N r2 r2_a F) 	

	
	

* =========================================================
* =========================================================
* 3. CABINET IDEOLOGY
* =========================================================
* =========================================================
* Based on ParlGov database, downloaded 30.5.2014

* Tables 1 and A5

/* Calculate average left-right score for party families and use if left-right score is not available
Left-right info from ParlGov database, dexcribed as 
"0--10 scale mean value in left/right dimension with data from Castles/Mair 1983, Huber/Inglehart 1995, Benoit/Laver 2006 and CHESS 2010"
*/

clear
use ParlGov.partydata.dta

* Generate Left-right score
* ------------------------------
gen family_lr=left_right

* all party families in which left-right values exceed a standard deviation of 2 are coded as missing
* not problematic because none of these parties are in any cabinets (if their actual position is unknown)
replace family_lr=. if family_name_short=="eth" // ethnic
replace family_lr=. if family_name_short=="reg" // regional
replace family_lr=. if family_name_short=="spec" // special interest
replace family_lr=. if family_name_short=="all" // electoral alliance
replace family_lr=. if family_name_short=="none" // no family
replace family_lr=. if family_name_short=="code" // to be coded


collapse (mean) family_lr  (first) family_name_short, by(family_name)
save partyfamilies.dta, replace

clear
use ParlGov.partydata.dta
merge m:1 family_name_short using partyfamilies.dta

drop _merge
gen lr_proxy=left_right
replace lr_proxy= family_lr if left_right==.

save parties.dta, replace


* Add proxied party ideology to cabinet data

clear
use parlgov.cabinets.dta
merge m:1 party_id using parties.dta


* Calculate left-right ideology for cabinet parties and aggregate onto cabinet level

gen cabseats=seats*cabinet_party

collapse (sum) cabseats, by(cabinet_id)
save cabinetseats.dta, replace

clear
use parlgov.cabinets.dta
merge m:1 cabinet_id using cabinetseats.dta
drop _merge
merge m:1 party_id using parties.dta
drop _merge

gen lrseats=seats*cabinet_party*lr_proxy
gen lrseats_orig=seats*cabinet_party*left_right


gen pctseats=seats/cabseats*cabinet_party

gen cabinetideology=lr_proxy*pctseats*cabinet_party
gen missingideology=cabinetideology==.
replace missingideology=0 if cabinet_party==0

gen cabinetideol_orig=left_right*pctseats*cabinet_party
gen missingideol_orig=cabinetideol_orig==.
replace missingideol_orig=0 if cabinet_party==0


collapse (sum) cabinetideology  missingideology cabinet_party (mean) country_id cabseats election_id (first) country_name cabinet_name election_date start_date, by(cabinet_id)


/* Special cases: 

1) Czech Republic (2009): interim government of Fischer , cabinet ID 157
 Note from Parlgov: 
 Interim PM Fischer was appointed on 9 April 2009 and the cabinet on 8 May. He was nominated by Civic Democratics (ODS), Social Democrats (CSSD), Greens (SZ) and won an investiture vote on 7 June (yes: 156).
Cabinet ended with election on 29 May 2010 and resigned on 25 June.

Civic Democratics (ODS)= 7.363728, 81 seats
Social Democrats (CSSD)=3.046287. 74 seats
Greens (SZ) = 4.122983, 6 seats

Proxy cabinet ideology: weighted average of these parties' ideologies: 5.258541019
*/

replace cabinetideology=5.258541019 if cabinet_id==157

/*
2) Italy (2011): Technocratic government by Mario Monti, ID 983
Coding decision: code as middle ground (5)
*/
replace cabinetideology=5 if cabinet_id==983

/*
3) Greece (2  ): Interim Government by Pikramenos, cabinet ID 1039
in office for only one month, coded as missing
*/

replace cabinetideology=. if cabinet_id==1039



gen cabideologynonmiss=cabinetideology
replace cabideologynonmiss=. if missingideology>0

gen cabinetyear = regexs(0) if regexm(start_date, "[0-9][0-9][0-9][0-9]")
destring cabinetyear, gen(cabyear)
gen electionyear = regexs(0) if regexm(election_date, "[0-9][0-9][0-9][0-9]")
destring cabinetyear, gen(elyear)


gen eesample=0
replace eesample=1 if country_id==10
replace eesample=1 if country_id==15
replace eesample=1 if country_id==23
replace eesample=1 if country_id==39
replace eesample=1 if country_id==55
replace eesample=1 if country_id==68
replace eesample=1 if country_id==74
replace eesample=1 if country_id==75



gen eurosample=0
replace eurosample=1 if country_id==51
replace eurosample=1 if country_id==37
replace eurosample=1 if country_id==41
replace eurosample=1 if country_id==63
replace eurosample=1 if country_id==27
replace eurosample=1 if country_id==43
replace eurosample=1 if country_id==26
label define eurosample 1 "EMU" 0 "EE"
label val eurosample eurosample

gen gipsc=0
replace gipsc=1 if country_id==51
replace gipsc=1 if country_id==37
replace gipsc=1 if country_id==41
replace gipsc=1 if country_id==63
replace gipsc=1 if country_id==27

sort country_id start_date

gen cabid_pre=cabinetideology if cabyear>2004 &cabyear<2009
gen cabid_preee=cabinetideology if cabyear>2003 &cabyear<2008
replace cabid_pre=cabid_preee if eesample==1

gen cabid_post=cabinetideology if cabyear>=2009 
gen cabid_postee=cabinetideology if cabyear>=2008 & cabyear<2012 
replace cabid_post=cabid_postee if eesample==1


gen pre=cabinetideology if cabyear>2003 &cabyear<2008
gen post=cabinetideology if cabyear>=2008 

* ----------------------------------------------------------------------------------------------
* TABLE 2: Overview about Government Composition and Policy Responses, 2007-10 (third column)
* APPENDIX TABLE A5: Government Composition, 2007-2010
* ----------------------------------------------------------------------------------------------

l country_name election_date start_date cabinet_name cabinetideolog cabinet_party if eesample==1 & cabyear>2004
	

			
log close




		
